// index.ts

import { AppContext } from "../../../app.context";
import { AppNotify, NotifyOption, NotifyType } from "../../../app.notify";
import { LoginService } from "../../../services/login.service";

Page({
  data: {
    name: '',
    password: ''
  },

  onLoad() {

  },
  onShow() {

  },

  getuserinfo() {
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res: any) => {
        wx.showLoading({
          title: '登录中...',
        })
        console.log(res);
        LoginService.instance.decryptionWX(res.encryptedData, res.iv).then(res => {
          console.log(res);
          AppContext.instance.user.setData(res.data);
          wx.showToast({
            title: '登录成功',
            icon: 'success'
          });
          setTimeout(() => {
            wx.switchTab({
              url: '/pages/index/index'
            })
            setTimeout(() => {
              AppNotify.instance.send(NotifyType.Login, NotifyOption.Empty, '');
            }, 100);
          }, 1300)
        });
      }
    })
  },


  /** 获取手机信息 暂无 */
  getPhoneNumber(e: any) {
    console.log(e.detail.errMsg)
    console.log(e.detail.iv)
    console.log(e.detail.encryptedData)
    LoginService.instance.decryptionWX(e.detail.encryptedData, e.detail.iv);
  }
})
